package net.jforum.controllers;

import javax.servlet.http.HttpServletResponse;

import net.jforum.entities.UserSession;
import net.jforum.util.Captcha;
import net.jforum.util.JForumConfig;
import br.com.caelum.vraptor.Resource;
import br.com.caelum.vraptor.Result;


@Resource
public class CaptchaController {
	
	private UserSession userSession;
	private HttpServletResponse response;
	private JForumConfig config;
	private final Result result;

	public CaptchaController(UserSession userSession,HttpServletResponse response
			,JForumConfig config, Result result) {
		this.userSession = userSession;
		this.response = response;
		this.config=config;
		this.result=result;
	}

	public void generate()	{
		userSession.createNewCaptcha(config);
		response.setContentType("image/jpg");
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
        response.setDateHeader("Expire", 0);
		Captcha.getInstance().writeCaptchaImage(userSession);
		this.result.nothing();
	}
}
